package com.situ.day2;

import org.junit.Test;

import java.util.Scanner;

public class Hello {

    //小驼峰
    @Test
    public void testAdd() {
        //byte short(char) int long
        //1、从小到大自动类型转换
        //2、从大到小需要强制类型转换，可能会丢失精度(装水的杯子大小不一样)
        char ch = 'a';
        System.out.println(ch);//a
        System.out.println(ch + 1);//97+1=98
        System.out.println(ch + 2);//97+2=99
        System.out.println((char)(ch + 1));//b
        System.out.println((char)(ch + 2));//b

        double d = 3.14;
        int num = (int)d;
        System.out.println(num);//3
    }

    @Test
    public void test2() {
        //双目运算符
        int num1 = 3;
        int num2 = 5;
        int result = num1 + num2;
        System.out.println(result);
        System.out.println(num1 - num2);
        System.out.println(num1 * num2);
        System.out.println(num1 / num2);

        System.out.println(8 / 2);//4
        System.out.println(8 % 2);//0
        System.out.println(8 / 5);//1
        System.out.println(8 % 5);//3
    }

    //单目运算符
    //num1++;
    @Test
    public void test4() {
        int num = 1;
        num = num + 1;
        System.out.println(num);
        //++(自增1)  --(自减1)
        int i = 1;
        i++;//++i;    i = i + 1;
        System.out.println(i);//2
        System.out.println(i++);//2
        System.out.println(i);//3
        System.out.println(++i);//4
    }

    //比较运算符
    @Test
    public void test5() {
        System.out.println(3 >= 5);//false
        System.out.println(5 < 10);//true
        System.out.println(5 == 10);//false
        System.out.println(5 <= 10);//true
        int num1 = 3;
        int num2 = 5;
        System.out.println(num1 != num2);//true

        boolean bool1 = num1 != num2;
        System.out.println(bool1);//true
        boolean bool2 = 3 >= 5;
        System.out.println(bool2);//false
    }

//    逻辑运算符
    @Test
    public void test6() {
        int score1 = 57;
        int score2 = 456;
        //比较运算符的优先级高于逻辑运算符
        //加了括号之后就不依赖默认优先级：()>比较元素安抚>逻辑运算符
        boolean result1 = (score1 >= 60) && (score2 >= 400);
        System.out.println(result1);//false
        boolean result2 = (score1 >= 60) || (score2 >= 400);
        System.out.println(result2);//true

        //短路
        int num1 = 3;
        int num2 = 5;
        //&&短路
        System.out.println(num1 < 0 | num1++ < num2);//false
        System.out.println(num1);//4
        System.out.println(num2);//5
    }


}
